package com.huzz.util.jieba;

import com.huaban.analysis.jieba.JiebaSegmenter;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Name 分词
 * @Description 描述
 * @Author 童年的纸飞机
 * @Since 2023-05-2023/5/6 15:35
 */
public class JieBaUtil {


    public List<String> participle(String text) {
        JiebaSegmenter jieBa = new JiebaSegmenter();

        List<String> textArray = jieBa.sentenceProcess(text);
        for (int i = textArray.size() - 1; i >= 0; i--) {
            if (textArray.get(i).length() == 1) {
                textArray.remove(i);
            }
        }
        return textArray.stream().sorted(Comparator.comparing(String::length).reversed()).collect(Collectors.toList());


    }

    public static void main(String[] args) {
        JiebaSegmenter jieBa = new JiebaSegmenter();
        /*多词*/
        String[] sentences =
                new String[] {"这是一个伸手不见五指的黑夜。我叫孙悟空，我爱北京，我爱Python和C++。", "我不喜欢日本和服。", "雷猴回归人间。",
                        "工信处女干事每月经过下属科室都要亲口交代24口交换机等技术性器件的安装工作", "结果婚的和尚未结过婚的"};
        for (String sentence : sentences) {
            String s = jieBa.process(sentence, JiebaSegmenter.SegMode.INDEX).toString();
            String s2 = s.replaceAll("\\[", "");
            String s1 = s2.replaceAll("^[0-9]*$", "");
            System.out.println(s1);
        }
    }
}
